package io.gitee.zhangbinhub.admin.controller.openinner

import io.gitee.zhangbinhub.acp.boot.log.LogAdapter
import io.gitee.zhangbinhub.admin.api.CommonPath
import io.gitee.zhangbinhub.admin.api.ServerApi
import io.gitee.zhangbinhub.admin.base.BaseController
import io.gitee.zhangbinhub.admin.entity.Organization
import io.gitee.zhangbinhub.admin.mapper.OrganizationMapper
import io.gitee.zhangbinhub.admin.service.OrganizationService
import io.gitee.zhangbinhub.admin.vo.OrganizationVo
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import org.noear.solon.annotation.Controller
import org.noear.solon.annotation.Inject
import org.noear.solon.annotation.Mapping
import org.noear.solon.core.handle.MethodType
import org.noear.solon.core.util.MimeType
import org.noear.solon.validation.annotation.Valid

@Valid
@Controller
@Api("机构信息（内部开放接口）")
open class OpenInnerOrgController(
    @Inject logAdapter: LogAdapter,
    private val organizationService: OrganizationService
) : BaseController(logAdapter) {
    private fun listToVo(organizationList: List<Organization>): List<OrganizationVo> =
        organizationList.map { organization -> OrganizationMapper.INSTANCE.entityToVo(organization) }

    @ApiOperation("获取机构列表", notes = "查询所有机构列表")
    @Mapping(
        method = [MethodType.GET],
        value = CommonPath.openInnerBasePath + ServerApi.orgConfig,
        produces = MimeType.APPLICATION_JSON_VALUE
    )
    fun orgList(): List<OrganizationVo> = listToVo(organizationService.getAllOrgList())
}